package com.weaver.openapi.service;

import com.weaver.openapi.pojo.crm.params.*;
import com.weaver.openapi.util.*;
import java.util.*;
import com.alibaba.fastjson.*;
import cn.hutool.http.*;
import com.weaver.openapi.pojo.crm.res.capital.*;
import com.weaver.openapi.pojo.*;

public class CrmCapitalService
{
    public static NormalRes<CrmCapitalResultVo> createCrmCapitalV2(final CrmVo crmVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", crmVo.getAccessToken());
        paramMap.put("userid", crmVo.getUserid());
        paramMap.put("module", crmVo.getModule());
        paramMap.put("entity", JSONObject.toJSONString((Object)crmVo.getCapitalEntity()));
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/crm/v2/create").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return transferResult(resJson);
    }
    
    public static MessageResult deleteCrmCapitalV2(final CrmVo crmVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", crmVo.getAccessToken());
        paramMap.put("userid", crmVo.getUserid());
        paramMap.put("module", crmVo.getModule());
        paramMap.put("id", crmVo.getId());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/crm/v2/delete").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (MessageResult)JSONObject.parseObject(resJson, (Class)MessageResult.class);
    }
    
    public static NormalRes<CrmCapitalResultVo> updateCrmCapitalV2(final CrmVo crmVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", crmVo.getAccessToken());
        paramMap.put("userid", crmVo.getUserid());
        paramMap.put("module", crmVo.getModule());
        paramMap.put("entity", JSONObject.toJSONString((Object)crmVo.getCapitalEntity()));
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/crm/v2/update").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return transferResult(resJson);
    }
    
    public static NormalRes<CrmCapitalResultVo> getCrmCapitalV2(final CrmVo crmVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final String resJson = ((HttpRequest)HttpRequest.get(host + String.format("/crm/v2/get?access_token=%s&userid=%s&module=%s&id=%s", crmVo.getAccessToken(), crmVo.getUserid(), crmVo.getModule(), crmVo.getId())).headerMap((Map)headers, true)).execute().body();
        return transferResult(resJson);
    }
    
    public static NormalRes<CrmCapitalSearchResultVo> searchCrmcapitalV2(final CrmVo crmVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final String resJson = ((HttpRequest)HttpRequest.get(host + String.format("/crm/v2/search?access_token=%s&userid=%s&module=%s&query=%s", crmVo.getAccessToken(), crmVo.getUserid(), crmVo.getModule(), JSONObject.toJSONString((Object)crmVo.getQuery()))).headerMap((Map)headers, true)).execute().body();
        return transferSearchResult(resJson);
    }
    
    public static RechargeCapitalResultVo rechargeCapitalV2(final CrmVo crmVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", crmVo.getAccessToken());
        paramMap.put("userid", crmVo.getUserid());
        paramMap.put("entity", JSONObject.toJSONString((Object)crmVo.getCapitalEntity()));
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/crm/v2/rechargeCapital").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (RechargeCapitalResultVo)JSONObject.parseObject(resJson, (Class)RechargeCapitalResultVo.class);
    }
    
    public static RechargeCapitalResultVo divertCapitalV2(final CrmVo crmVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", crmVo.getAccessToken());
        paramMap.put("userid", crmVo.getUserid());
        paramMap.put("entity", JSONObject.toJSONString((Object)crmVo.getCapitalEntity()));
        paramMap.put("capital", crmVo.getUserid());
        paramMap.put("capitalCustomer", crmVo.getUserid());
        paramMap.put("capitalAccount", crmVo.getUserid());
        paramMap.put("accountAmount", crmVo.getUserid());
        paramMap.put("accountOperTime", crmVo.getUserid());
        paramMap.put("accountDescription", crmVo.getUserid());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/crm/v2/divertCapital").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (RechargeCapitalResultVo)JSONObject.parseObject(resJson, (Class)RechargeCapitalResultVo.class);
    }
    
    public static NormalRes<CrmCapitalSearchResultVo> transferSearchResult(final String resJson) {
        final JSONObject jsonObject = JSONObject.parseObject(resJson);
        final CrmCapitalSearchResultVo data = (CrmCapitalSearchResultVo)jsonObject.getObject("data", (Class)CrmCapitalSearchResultVo.class);
        final NormalResult message = (NormalResult)jsonObject.getObject("message", (Class)NormalResult.class);
        final NormalRes<CrmCapitalSearchResultVo> normalRes = new NormalRes<CrmCapitalSearchResultVo>();
        normalRes.setData(data);
        normalRes.setMessage(message);
        return normalRes;
    }
    
    public static NormalRes<CrmCapitalResultVo> transferResult(final String resJson) {
        final JSONObject jsonObject = JSONObject.parseObject(resJson);
        final CrmCapitalResultVo data = (CrmCapitalResultVo)jsonObject.getObject("data", (Class)CrmCapitalResultVo.class);
        final NormalResult message = (NormalResult)jsonObject.getObject("message", (Class)NormalResult.class);
        final NormalRes<CrmCapitalResultVo> normalRes = new NormalRes<CrmCapitalResultVo>();
        normalRes.setData(data);
        normalRes.setMessage(message);
        return normalRes;
    }
}
